package cn.shyouchi.wuguanjia.android.ui.event;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.base.BaseActivity;
import cn.shyouchi.wuguanjia.android.model.EventInfoModel;
import cn.shyouchi.wuguanjia.android.ui.event.arrange.EventArrangeActivity;
import cn.shyouchi.wuguanjia.android.ui.event.check.EventCheckActivity;
import cn.shyouchi.wuguanjia.android.ui.event.checknum.CheckNumManageActivity;
import cn.shyouchi.wuguanjia.android.ui.event.checkpoint.EventCheckPointActivity;
import cn.shyouchi.wuguanjia.android.ui.event.handover.HandoverManagerActivity;
import cn.shyouchi.wuguanjia.android.ui.event.labor.EventLaborActivity;
import cn.shyouchi.wuguanjia.android.ui.event.meet.EventMeetActivity;
import cn.shyouchi.wuguanjia.android.ui.event.post.EventPostActivity;
import cn.shyouchi.wuguanjia.android.ui.event.proprietor.EventProprietorActivity;
import cn.shyouchi.wuguanjia.android.ui.event.rank.EventRankActivity;
import cn.shyouchi.wuguanjia.android.ui.event.report.EventReportActivity;
import cn.shyouchi.wuguanjia.android.ui.event.temporary.EventTemporaryActivity;
import cn.shyouchi.wuguanjia.android.ui.event.train.EventTrainActivity;
import cn.shyouchi.wuguanjia.android.widget.TopBar;
import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.RuntimePermissions;

@RuntimePermissions
public class EventCompileActivity extends BaseActivity implements EventCompileContract.View {


    @BindView(R.id.topBar)
    TopBar topBar;
    @BindView(R.id.rv_events)
    RecyclerView rvEvents;
    EventInfoAdapter mAdapter;
    List<EventInfoModel> models = new ArrayList<>();
    String eventName;
    String projectId;


    public static void start(Context context, String id, String name) {
        Intent intent = new Intent(context, EventCompileActivity.class);
        intent.putExtra("id", id);
        intent.putExtra("name", name);
        context.startActivity(intent);
    }


    @Override
    public int initContentView() {
        return R.layout.activity_event_setting;
    }

    @Override
    public void initInjector() {
        eventName = getIntent().getStringExtra("name");
        projectId = getIntent().getStringExtra("id");
    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);
        topBar.setTitle(eventName);
        topBar.setLeftIcon(R.mipmap.ic_back);
        setSupportActionBar(topBar.getToolbar());
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_PROPRIETOR, "关键人物信息设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_HANDOVER, "交接班注意事项设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_TRAIN, "岗位培训设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_TEMP, "临保设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_RANK, "班次设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_CHECK, "考勤设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_LABOR, "项目工时设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_ARRANGE, "排班设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_POST, "岗位设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_REPORT, "报岗设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_CHECK_POINT, "巡检点设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_CHECK_NUM, "巡检线路设置"));
        models.add(new EventInfoModel(EventInfoModel.EVENT_TYPE_MEET, "班会设置"));
        mAdapter = new EventInfoAdapter(models, this);
        rvEvents.setLayoutManager(new LinearLayoutManager(this));
        rvEvents.setAdapter(mAdapter);
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isApplyStatusBarColor() {
        return true;
    }


    @NeedsPermission({Manifest.permission.ACCESS_COARSE_LOCATION})
    public void gotoCheck(Intent intent) {
        intent.setClass(mContext, EventCheckActivity.class);
        startActivity(intent);
    }


    @Override
    public void infoItemClick(EventInfoModel model) {

        Intent intent = new Intent();
        intent.putExtra("projectId", projectId);
        switch (model.getType()) {
            case EventInfoModel.EVENT_TYPE_PROPRIETOR:
                intent.setClass(mContext, EventProprietorActivity.class);
                startActivity(intent);
                break;
            case EventInfoModel.EVENT_TYPE_HANDOVER:
                intent.setClass(mContext, HandoverManagerActivity.class);
                startActivity(intent);
                break;
            case EventInfoModel.EVENT_TYPE_TRAIN:
                intent.setClass(mContext, EventTrainActivity.class);
                startActivity(intent);
                break;
            case EventInfoModel.EVENT_TYPE_RANK:
                intent.setClass(mContext, EventRankActivity.class);
                startActivity(intent);
                break;
            case EventInfoModel.EVENT_TYPE_CHECK:
                EventCompileActivityPermissionsDispatcher.gotoCheckWithCheck(this, intent);
                break;

            case EventInfoModel.EVENT_TYPE_LABOR:
                intent.setClass(mContext, EventLaborActivity.class);
                startActivity(intent);
                break;
            case EventInfoModel.EVENT_TYPE_ARRANGE:
                intent.setClass(mContext, EventArrangeActivity.class);
                startActivity(intent);
                break;
            case EventInfoModel.EVENT_TYPE_POST:
                intent.setClass(mContext, EventPostActivity.class);
                startActivity(intent);
                break;
            case EventInfoModel.EVENT_TYPE_REPORT:
                intent.setClass(mContext, EventReportActivity.class);
                startActivity(intent);
                break;
            case EventInfoModel.EVENT_TYPE_CHECK_POINT:
                intent.setClass(mContext, EventCheckPointActivity.class);
                startActivity(intent);
                break;
            case EventInfoModel.EVENT_TYPE_CHECK_NUM:
                intent.setClass(mContext, CheckNumManageActivity.class);
                startActivity(intent);
                break;
            case EventInfoModel.EVENT_TYPE_MEET:
                intent.setClass(mContext, EventMeetActivity.class);
                startActivity(intent);
                break;
            case EventInfoModel.EVENT_TYPE_TEMP:
                intent.setClass(mContext, EventTemporaryActivity.class);
                startActivity(intent);
                break;
            default:
                intent.setClass(mContext, EventProprietorActivity.class);
                startActivity(intent);
                break;
        }


    }


}
